home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1999 January / maximum-cd-1999-01.iso / Benchmarks / 12 Step / MusicMatch Jukebox / mmsetup.EXE / data1.cab / Help_Files / WebHelp.cab / treeview / SiblingChildTree.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-27  |  1.8 KB  |  173 lines

  1. package treeview;
  2.  
  3. public class SiblingChildTree {
  4.    protected SiblingChildTree parent = null;
  5.    protected SiblingChildTree sibling_left = null;
  6.    protected SiblingChildTree sibling_right = null;
  7.    protected SiblingChildTree child = null;
  8.  
  9.    public SiblingChildTree getChild() {
  10.       return this.child;
  11.    }
  12.  
  13.    public SiblingChildTree pruneThisSubtree() {
  14.       if (this.sibling_left != null) {
  15.          this.sibling_left.sibling_right = this.sibling_right;
  16.          if (this.sibling_right != null) {
  17.             this.sibling_right.sibling_left = this.sibling_left;
  18.          }
  19.       } else if (this.sibling_right != null) {
  20.          this.sibling_right.sibling_left = null;
  21.          if (this.parent != null) {
  22.             this.parent.child = this.sibling_right;
  23.          }
  24.       }
  25.  
  26.       SiblingChildTree var1;
  27.       for(var1 = this; var1.parent != null; var1 = var1.parent) {
  28.       }
  29.  
  30.       while(var1.sibling_left != null) {
  31.          var1 = var1.sibling_left;
  32.       }
  33.  
  34.       if (var1 == this) {
  35.          var1 = this.sibling_right;
  36.       }
  37.  
  38.       this.parent = null;
  39.       this.sibling_left = null;
  40.       this.sibling_right = null;
  41.       return var1;
  42.    }
  43.  
  44.    protected void setParent(SiblingChildTree var1) {
  45.       this.parent = var1;
  46.       if (this.sibling_right != null) {
  47.          this.sibling_right.setParent(var1);
  48.       }
  49.  
  50.    }
  51.  
  52.    public SiblingChildTree getParent() {
  53.       return this.parent;
  54.    }
  55.  
  56.    public SiblingChildTree nextNode() {
  57.       if (this.child != null) {
  58.          return this.child;
  59.       } else if (this.sibling_right != null) {
  60.          return this.sibling_right;
  61.       } else {
  62.          for(SiblingChildTree var1 = this.parent; var1 != null; var1 = var1.parent) {
  63.             if (var1.sibling_right != null) {
  64.                return var1.sibling_right;
  65.             }
  66.          }
  67.  
  68.          return null;
  69.       }
  70.    }
  71.  
  72.    public SiblingChildTree getSibling() {
  73.       return this.sibling_right;
  74.    }
  75.  
  76.    public SiblingChildTree prevNode() {
  77.       if (this.sibling_left == null) {
  78.          return this.parent != null ? this.parent : null;
  79.       } else {
  80.          SiblingChildTree var1 = this.sibling_left.child;
  81.          if (var1 == null) {
  82.             return this.sibling_left;
  83.          } else {
  84.             while(var1.sibling_right != null) {
  85.                var1 = var1.sibling_right;
  86.             }
  87.  
  88.             return var1;
  89.          }
  90.       }
  91.    }
  92.  
  93.    public SiblingChildTree[] getChildren() {
  94.       SiblingChildTree[] var1 = new SiblingChildTree[this.numberOfChildren()];
  95.       SiblingChildTree var2 = this.child;
  96.  
  97.       for(int var3 = 0; var3 < var1.length; ++var3) {
  98.          var1[var3] = var2;
  99.          var2 = var2.sibling_right;
  100.       }
  101.  
  102.       return var1;
  103.    }
  104.  
  105.    public int numberOfChildren() {
  106.       int var1 = 0;
  107.  
  108.       for(SiblingChildTree var2 = this.child; var2 != null; var2 = var2.sibling_right) {
  109.          ++var1;
  110.       }
  111.  
  112.       return var1;
  113.    }
  114.  
  115.    public SiblingChildTree pruneChildren() {
  116.       if (this.child == null) {
  117.          return null;
  118.       } else {
  119.          this.child.setParent((SiblingChildTree)null);
  120.          SiblingChildTree var1 = this.child;
  121.          this.child = null;
  122.          return var1;
  123.       }
  124.    }
  125.  
  126.    public boolean isSibling(SiblingChildTree var1) {
  127.       if (this == var1) {
  128.          return false;
  129.       } else {
  130.          SiblingChildTree var2;
  131.          for(var2 = this; var2.sibling_left != null; var2 = var2.sibling_left) {
  132.          }
  133.  
  134.          while(var2 != null) {
  135.             if (var2 == var1) {
  136.                return true;
  137.             }
  138.  
  139.             var2 = var2.sibling_right;
  140.          }
  141.  
  142.          return false;
  143.       }
  144.    }
  145.  
  146.    public void addChild(SiblingChildTree var1) {
  147.       if (var1 == null) {
  148.          throw new IllegalArgumentException("SiblingChildTree.addChild(): child is a null reference");
  149.       } else if (this.child == null) {
  150.          this.child = var1;
  151.          var1.setParent(this);
  152.       } else {
  153.          this.child.addSibling(var1);
  154.       }
  155.    }
  156.  
  157.    public SiblingChildTree getSiblingLeft() {
  158.       return this.sibling_left;
  159.    }
  160.  
  161.    public void addSibling(SiblingChildTree var1) {
  162.       if (var1 == null) {
  163.          throw new IllegalArgumentException("SiblingChildTree.addSibling(): sibling is a null reference");
  164.       } else if (this.sibling_right == null) {
  165.          this.sibling_right = var1;
  166.          var1.sibling_left = this;
  167.          var1.setParent(this.parent);
  168.       } else {
  169.          this.sibling_right.addSibling(var1);
  170.       }
  171.    }
  172. }
  173.